#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QAudioSource>
#include <QMediaDevices>
#include <QAudioFormat>
#include <QIODevice>
#include <QFile>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    QAudioSource *audioSource;
    Ui::MainWindow *ui;
};

/******************************** Audio file **********************************/

/**
 * \brief QAudioSource的输出必须是QIODevice
 */
class AudioFile : public QIODevice
{
    Q_OBJECT

public:
    AudioFile(const QAudioFormat &format);
    void start();
    void stop();
    qint64 readData(char *data, qint64 maxlen) override;
    qint64 writeData(const char *data, qint64 len) override;

private:
    const QAudioFormat m_format;
    QFile file;
    int total = 0;
};

#endif // MAINWINDOW_H
